package com.tiny.mirror.service.product.support.strategy.lhc;

import com.google.common.collect.Lists;
import com.tiny.mirror.basic.common.code.CommonStatusCode;
import com.tiny.mirror.basic.web.exception.BusinessException;
import com.tiny.mirror.service.product.common.util.AbilityLhcPlayUtil;
import com.tiny.mirror.service.product.domain.ability.LhcParams.LhcItemParams;
import com.tiny.mirror.service.product.domain.ability.LhcParams.LhcPlayParams;
import com.tiny.mirror.service.product.enums.AbilityLhcCategoryEnum;
import com.tiny.mirror.service.product.enums.AbilityLhcStrategyEnum;
import com.tiny.mirror.service.product.support.strategy.lhc.dto.LhcNumberDTO;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import org.springframework.stereotype.Component;

@Component
public class LhcPszsStrategy extends LhcTmapStrategy {

  @Override
  public AbilityLhcStrategyEnum strategy() {
    return AbilityLhcStrategyEnum.PSZS;
  }

  @Override
  public LhcPlayParams build() {
    LhcPlayParams params = new LhcPlayParams();
    params.setCode("tm-pszs");
    params.setRule(
        "选择3个或3个以上号码，开奖号码的正码包含所选号码，即中奖\n"
            + "例如：投注方案04、22、25\n开奖号码为：04,25,36,22,44,30 + 45，即为三全中。"
    );
    params.setPlay(AbilityLhcStrategyEnum.PSZS.getName());
    params.setCategory(AbilityLhcCategoryEnum.PM);
    params.setStrategy(AbilityLhcStrategyEnum.PSZS);
    params.setLimit(3);
    params.setRewardPercent(BigDecimal.ZERO);
    params.setOdds(new BigDecimal("650"));
    List<LhcItemParams> itemParamsList = Lists.newArrayList();
    AbilityLhcPlayUtil.NUMBER.stream().forEach(i -> {
      LhcItemParams itemParams = new LhcItemParams();
      itemParams.setItem(String.valueOf(i));
      itemParamsList.add(itemParams);
    });
    params.setItemList(itemParamsList);
    return params;
  }

  @Override
  public BigDecimal calculate(
      LhcPlayParams lhcPlayParams, BigDecimal amount, LhcNumberDTO result, String... item
  ) {
    checkAmount(amount);
    checkItem(3, item[0], item[1], item[2]);
    // todo
    return match(lhcPlayParams, amount, result, item[0]);
  }

  @Override
  public void checkItem(Integer limit, String... item) {
    // todo
    if (Arrays.stream(item).anyMatch(i -> !AbilityLhcPlayUtil.NUMBER.contains(i))) {
      throw new BusinessException(CommonStatusCode.COMMON_ERROR);
    }
  }
}
